package edu.uci.ics.ai.maze.models;

import java.awt.Color;
import java.util.Collections;
import java.util.List;

public class Polygon implements Cloneable {

  /**
   *  List of all nodes in the polygon
   */
  private final List<Vertex> vertices;
  /**
   * List of all edges in the polygon
   */
  private final Edge[] edges;
  private final Color color;

  public Polygon(List<Vertex> vertices, Color color) {
    int totalEdges = vertices.size();
    this.color = color;
    this.edges = new Edge[totalEdges];

    for (Vertex v : vertices) {
      v.setPolygon(this);
    }
    this.vertices = Collections.unmodifiableList(vertices);

    for (int i = 1; i < totalEdges; i++) {
      edges[i - 1] = new Edge(vertices.get(i - 1), vertices.get(i));
    }
    edges[totalEdges - 1] = new Edge(vertices.get(totalEdges - 1), vertices.get(0));
  }

  /**
   * Returns the number of edges in the polygon.
   * 
   * @return the number of edges
   */
  public int getEdgesCount() {
    return edges.length;
  }

  /**
   * @return the vertexes
   */
  public List<Vertex> getVertices() {
    return vertices;
  }

  /**
   * @return the edges
   */
  public Edge[] getEdges() {
    return edges;
  }

  /**
   * Returns the color of the Polygon.
   * 
   * @return the color of the Polygon
   */
  public Color getColor() {
    return color;
  }
}
